<template>
  <div>

    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">变更后里程碑节点</span>
      <van-button v-if="canAppendLCB" block type="primary" style="display: inline-block;width:auto;height: 33px;"
        native-type="button" @click="milestoneListHandleAppend()">新增</van-button>
    </div>
    <el-table :data="fromdata.milestoneList" border style="width: 100%" :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }">
      <el-table-column prop="milestoneNode" label="里程碑节点" width="100" />
      <el-table-column prop="milestoneDescription" label="里程碑描述" width="150" />
      <el-table-column prop="planEndDate" label="里程碑计划完成时间" width="150" />
      <el-table-column prop="contractArrangePayTime" label="合同约定交付时间" width="150" />
      <el-table-column prop="planPersonName" label="计划交付人姓名" width="120" />
      <el-table-column prop="planPersonOA" label="计划交付人OA账户" width="150" />
      <el-table-column prop="fjProveFile" label="分解证明资料" width="110">
        <template slot-scope="scope">
          <span readonly class="font14" style="color:#0F85CF">
            {{ scope.row.fjProveFile ? scope.row.fjProveFile[0].fileName : "" }}
          </span>
        </template>
      </el-table-column>
      <el-table-column v-if="canAppendLCB" label="操作" width="150">


        <!-- slot-scope="scope" //取到当前单元格 
                scope.$index //拿到当前行的index
                scope.row //拿到当前行的数据对象 -->
        <template slot-scope="scope">
          <div style="white-space: nowrap; display: inline-block">
            <el-button type="primary" size="small"
              @click="milestoneListHandleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button type="danger" size="small"
              @click="milestoneListHandleDelete(scope.$index, scope.row)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>


    <section-header :sectionTitle="'环节信息'"></section-header>
    <el-table :data="fromdata.linkInfo" border style="width: 100%" :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }">
      <el-table-column prop="LINKNAME" label="环节编码" width="90" />
      <el-table-column prop="STARTTIME" label="环节开始时间" width="110" />
      <el-table-column prop="ENDTIME" label="环节结束时间" width="110" />
      <el-table-column prop="LINKDESC" label="环节描述" width="90" />
    </el-table>

    <section-header :sectionTitle="'合同信息'"></section-header>
    <el-table :data="fromdata.contractInfo" border style="width: 100%" :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }">
      <el-table-column prop="contractType" label="收支类型" width="90" />
      <el-table-column prop="contractNumber" label="合同编码" width="90" />
      <el-table-column prop="contractName" label="合同名称" width="200" />
      <el-table-column prop="contractAmount" label="合同含税金额（元）" width="150" />
    </el-table>

    <section-header :sectionTitle="'效益评估'"></section-header>
    <el-table :data="fromdata.benefitInfo" border style="width: 100%" :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }">
      <el-table-column prop="title" label="效益评估阶段" width="110" />
      <el-table-column prop="gBudget" label="概算" width="60" />
      <el-table-column prop="yBudget" label="预算" width="60" />
      <el-table-column prop="hBudget" label="核算（变更前）" width="120" />
      <el-table-column prop="bBudget" label="核算（变更后）" width="120" />
    </el-table>

    <div style="padding-bottom: 42px"></div>


  </div>
</template>


<script>

import { openFileUrl } from '@/store/openFile'
import sectionHeader from '../sztdzj/sztdzjDetail/section-header.vue'
import { Append_lcb_KEY, ChooseSJ_KEY } from "../../assets/js/dict_process_helper"
import jTool from "../../assets/js/jHelper"
import { milestoneFindAllByProjectId, projectChangeModelFindByBusinessId, projectChangeModelFindByProjectId } from "../../api/dictapi"
import { Dialog, Notify, Toast } from "vant"


export default {
  components: { sectionHeader },
  data() {
    return {

      isAppend: false,     //是否新增 或编辑
      pushAppendIndex: 0,
    }
  },

  computed: {

    /// 可以新增里程碑节点
    canAppendLCB() {

      return this.pushParams.isDrawup == '1' || this.pushParams.location == 'dict.start';
    },

    /// 选择商机后  表格数据会刷新
    canChooseSJ() {

      return this.pushParams.isDrawup == '1' || this.pushParams.location == 'dict.start';
    },

  },

  props: ['pushParams', 'fromdata'],


  created() {


  },

  activated() {


    if (this.canChooseSJ) {

      if (localStorage.getItem(Append_lcb_KEY) != '{}' &&
        localStorage.getItem(Append_lcb_KEY)) {

        console.log('里程碑数据新增：', this.fromdata, this.fromdata.milestoneList);
        let lcbInfo = JSON.parse(localStorage.getItem(Append_lcb_KEY));
        localStorage.setItem(Append_lcb_KEY, '{}')

        if (this.fromdata.milestoneList == null || this.fromdata.milestoneList == undefined) {
          this.fromdata.milestoneList = [];
        }

        if (this.isAppend) {
          this.fromdata.milestoneList.push(lcbInfo);
        }
        else {
          this.fromdata.milestoneList[this.pushAppendIndex] = lcbInfo;
          this.$forceUpdate();
        }

        this.isAppend = false;
      }
    }
  },

  watch: {

  },
  methods: {




    openFileUrlfun(value) {
      this.$router.push(
        {
          name: 'fileview',
          query: {
            openFileUrl: openFileUrl(value)
          }
        }
      );
    },

    /// 网络请求 "变更后里程碑节点" "效益评估、环节信息" "合同信息"
    requstDrawupInfo() {

      let processID = this.fromdata.projectID;
      let businessId = this.fromdata.businessId;
      Toast.loading({ message: "加载中", forbidClick: false });

      // 变更后里程碑节点
      milestoneFindAllByProjectId(processID).then((result) => {
        Toast.clear();
        if (!result.data) {
          Notify(result.message);
          return;
        }

        if (result.data.data) {
          let content = result.data.data;
          if (content && content.length > 0) {
            this.fromdata.milestoneList = content;
          }
        }
      });

      // 效益评估、环节信息
      projectChangeModelFindByBusinessId(businessId).then((result) => {
        Toast.clear();
        if (!result.data) {
          Notify(result.message);
          return;
        }

        let dict = result.data.data;
        if (dict) {
          this.fromdata.benefitInfo = dict.benefitInfo;
          this.fromdata.linkInfo = dict.linkInfo;
        }
      });

      // 合同信息
      projectChangeModelFindByProjectId(processID).then((result) => {
        Toast.clear();
        if (!result.data) {
          Notify(result.message);
          return;
        }

        let dict = result.data.data;
        if (dict) {
          this.fromdata.contractInfo = dict.contractInfo;
        }
      });

    },




    milestoneListHandleDelete(index, row) {

      Dialog.confirm({
        title: '提示',
        message: '确定删除吗？',
      }).then(() => {
        this.fromdata.milestoneList.splice(index, 1);
      });
    },

    milestoneListHandleEdit(index, row) {

      this.isAppend = false;
      this.pushAppendIndex = index;
      this.pushAppendLCBInfo(row);
    },

    milestoneListHandleAppend() {

      this.isAppend = true;
      this.pushAppendIndex = 0;
      this.pushAppendLCBInfo({});
    },

    // “新增里程碑”
    pushAppendLCBInfo(row) {

      var params = Object.assign({}, this.pushParams);
      params.formData = row;
      this.$router.push(
        {
          name: 'apc_append_lcb',
          query: params,
        }
      )
    },

  },

}
</script>

<style></style>